//
//  studentViewController.m
//  CoreData2
//
//  Created by ibokan on 14-11-5.
//  Copyright (c) 2014年 ibokan. All rights reserved.
//

#import "studentViewController.h"
#import "Student.h"
#import "AppDelegate.h"
@interface studentViewController ()

@end

@implementation studentViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)save:(UIBarButtonItem *)sender {
    AppDelegate *delegate = [UIApplication sharedApplication].delegate;
    
    NSManagedObjectContext *context = delegate.managedObjectContext;
    Student *student = [NSEntityDescription insertNewObjectForEntityForName:@"Student" inManagedObjectContext:context];
    student.stdName = self.stdNameTextField.text;
    student.stdNo = self.stdNoTextField.text;
    student.classmate = self.classmateTextField.text;
    if (![context save:nil]) {
        NSLog(@"---------------");
    }
    [self.navigationController popViewControllerAnimated:YES];
}
@end
